<template>
  <div class="page_recommend">
    <div class="title1">
      <!-- <span>成都伊登，</span> -->
      <span class="title1_1">智能体助手</span>
    </div>
    <div class="title2">
      <span>不仅可以为你撰写文章、提供灵感，还能陪你交流互动，解答各种问题。</span>
      <span class="title1_1 title2_1" @click="refreshClick">
        换一换
        <i class="el-icon-refresh-left title1_1"></i>
      </span>
    </div>
    <div class="page_body">
      <div class="item_box" v-for="(item, index) in tableData" :key="index" @click="enterInfoClick(item, index)">
        <div class="triangle_box">
          <div class="triangle_icon"
            :style="{ backgroundColor: `rgba(${item.bgColor},.15)`, color: `rgb(${item.fontColor})` }">
            {{ item.titleText }}
          </div>
        </div>
        <div class="titleName">{{ item.titleName }}</div>
        <div class="titleDesc">
          {{ item.desc }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="yu-context-recommend-new" lang="ts">
import chatAgentApi from '@/api/chatgpt/chatAgentApi';
import useUserStore from '@/store/modules/user';
const tableLoading = ref(false)
const tableData = ref([])
const requestStr = ref({
  page: 0,
  size: 4,
  total: 0,
  pageCount: 0
})
const userStore = useUserStore();

const emit = defineEmits(['enterInfoClick'])
const getTableData=()=> {
  tableLoading.value = true;
  chatAgentApi
    .apiHelperGet({
      page: requestStr.value.page,
      size: requestStr.value.size,
      // sort: "id,desc"
    })
    .then((result:any) => {
      tableLoading.value = false;
      requestStr.value.total = result.total;
      requestStr.value.pageCount = result.pageSize;
      tableData.value = result.rows;
    })
    .catch((err) => {
      tableLoading.value = false;
    });
}
const refreshClick=()=> {
  requestStr.value.page++;
  if (requestStr.value.page > requestStr.value.pageCount) {
    requestStr.value.page = 1;
  }
  getTableData();
}
// 点击了进入
const enterInfoClick=(item:any, index:any)=> {
  emit("enterInfoClick", item);
}
onMounted(() => {
  getTableData();
});
</script>

<style scoped lang="scss">
@mixin textOverflow($clamp) {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: $clamp; //元素几行显示
  -webkit-box-orient: vertical;
}

.page_recommend {
  .title1 {
    font-size: 34px;
    color: #3d3d3d;
    font-weight: bold;
    text-align: center;
    margin-bottom: 22px;
  }

  .title1_1 {
    color: #3662ec;
  }

  .title2 {
    font-size: 21px;
    color: #3d3d3d;
    text-align: center;
    margin-bottom: 30px;
  }

  .title2_1 {
    cursor: pointer;
  }

  .page_body {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;

    .item_box {
      padding: 18px 15px;
      border-radius: 16px;
      background: #ffffff;
      transition: box-shadow 0.3s;
      cursor: pointer;

      &:hover {
        box-shadow: 0px 8px 32px 0px rgba(0, 0, 0, 0.16);
      }
    }

    .triangle_box {
      width: 25px;
      height: 25px;
      background-color: #ffffff;
      border-radius: 50%;
      margin-right: 6px;

      .triangle_icon {
        width: 25px;
        height: 25px;
        border-radius: 50%;
        line-height: 25px;
        text-align: center;
        font-size: 14px;
      }
    }

    .titleName {
      font-size: 16px;
      color: #2c2c36;
      margin: 10px 0;
      width: 100%;
      @include textOverflow(1);
    }

    .titleDesc {
      font-size: 13px;
      color: #666666;
      font-weight: 500;
      line-height: 18px;
      height: 72px;
      @include textOverflow(4);
    }
  }
}
</style>
